package com.feidee.data.report.model;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class CustomReportModel {

	private String id; // 任务ID
	private String applysqlname; // 报表名称
	private String period; // 报表执行
	private String priority; // 报表优先级
	private Map<String, ColumnInfoModel> mysqlColumn; // Mysql表列信息
	private Map<String, SqlInfoModel> hivesql; // hivesql语句信息
	private String applyname; // 报表中文名称
	private String reportDependency; //报表依赖
	private String dataResources; //数据源
	private String enable; //报表状态，前端提交报表该值设置为0，用于区别执行的资源池

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getApplysqlname() {
		return applysqlname;
	}

	public void setApplysqlname(String applysqlname) {
		this.applysqlname = applysqlname;
	}

	public String getPeriod() {
		return period;
	}

	public void setPeriod(String period) {
		this.period = period;
	}

	public Map<String, ColumnInfoModel> getMysqlColumn() {
		return mysqlColumn;
	}

	public void setMysqlColumn(Map<String, ColumnInfoModel> mysqlColumn) {
		this.mysqlColumn = mysqlColumn;
	}

	public Map<String, SqlInfoModel> getHivesql() {
		return hivesql;
	}

	public void setHivesql(Map<String, SqlInfoModel> hivesql) {
		this.hivesql = hivesql;
	}


	public String getApplyname() {
		return applyname;
	}

	public void setApplyname(String applyname) {
		this.applyname = applyname;
	}

	public String getReportDependency() {
		return reportDependency == null ? "" : reportDependency;
	}

	public void setReportDependency(String reportDependency) {
		this.reportDependency = reportDependency;
	}

	public String getDataResources() {
		return dataResources;
	}

	public void setDataResources(String dataResources) {
		this.dataResources = dataResources;
	}

	public void setEnable(String enable) {
		this.enable = enable;
	}

	public String getEnable() {
		return enable;
	}

	public String getPriority() {
		return priority;
	}

	public void setPriority(String priority) {
		this.priority = priority;
	}

	@Override
	public String toString() {
		return "CustomReportModel{" +
				"id='" + id + '\'' +
				", applysqlname='" + applysqlname + '\'' +
				", period='" + period + '\'' +
				", priority='" + priority + '\'' +
				", mysqlColumn=" + mysqlColumn +
				", hivesql=" + hivesql +
				", applyname='" + applyname + '\'' +
				", reportDependency='" + reportDependency + '\'' +
				", dataResources='" + dataResources + '\'' +
				", enable='" + enable + '\'' +
				'}';
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		CustomReportModel that = (CustomReportModel) o;

		if (id != null ? !id.equals(that.id) : that.id != null) return false;
		if (applysqlname != null ? !applysqlname.equals(that.applysqlname) : that.applysqlname != null) return false;
		if (priority != null ? !priority.equals(that.priority) : that.priority != null) return false;
		if (period != null ? !period.equals(that.period) : that.period != null) return false;
		if (mysqlColumn != null ? !mysqlColumn.equals(that.mysqlColumn) : that.mysqlColumn != null) return false;
		if (hivesql != null ? !hivesql.equals(that.hivesql) : that.hivesql != null) return false;
		if (applyname != null ? !applyname.equals(that.applyname) : that.applyname != null) return false;
		if (dataResources != null ? !dataResources.equals(that.dataResources) : that.dataResources != null) return false;
		return reportDependency != null ? reportDependency.equals(that.reportDependency) : that.reportDependency == null;

	}

	@Override
	public int hashCode() {
		int result = id != null ? id.hashCode() : 0;
		result = 31 * result + (applysqlname != null ? applysqlname.hashCode() : 0);
		result = 31 * result + (period != null ? period.hashCode() : 0);
		result = 31 * result + (priority != null ? priority.hashCode() : 0);
		result = 31 * result + (mysqlColumn != null ? mysqlColumn.hashCode() : 0);
		result = 31 * result + (hivesql != null ? hivesql.hashCode() : 0);
		result = 31 * result + (applyname != null ? applyname.hashCode() : 0);
		result = 31 * result + (reportDependency != null ? reportDependency.hashCode() : 0);
		result = 31 * result + (dataResources != null ? dataResources.hashCode() : 0);
		return result;
	}

	public static void main(String[] args) {
		CustomReportModel customReportModel = new CustomReportModel();
		customReportModel.setId("265482");
		customReportModel.setPeriod("D10");
		customReportModel.setApplyname("自定义报表测试");
		customReportModel.setApplysqlname("zkj_custom_test");
		Map<String, SqlInfoModel> hivesql = new HashMap<String, SqlInfoModel>();
		SqlInfoModel sqlInfoModel = new SqlInfoModel();
		sqlInfoModel.setSqlType("insert");
		sqlInfoModel.setSqlContent(
				"select fname AS fname, fid AS fid, ffrom AS ffrom from dw.bdl_ssj_feidee_user limit 10");
		sqlInfoModel.setSqlHistory(
				"select fname AS fname, fid AS fid, ffrom AS ffrom from dw.bdl_ssj_feidee_user limit 100");
		sqlInfoModel.setSqlSource("hive");
		hivesql.put("sql1", sqlInfoModel);
		SqlInfoModel sqlInfoModel1 = new SqlInfoModel();
		sqlInfoModel1.setSqlType("insert");
		sqlInfoModel1.setSqlContent(
				"select \"zkj2156456465\" AS fname, \"zkj2156456465\" AS fid, \"zkj2156456465\" AS ffrom from zkj_custom_test");
		sqlInfoModel1.setSqlHistory(
				"select \"zkj2156456465\" AS fname, \"zkj2156456465\" AS fid, \"zkj2156456465\" AS ffrom from zkj_custom_test");
		sqlInfoModel1.setSqlSource("mysql");
		hivesql.put("sql2", sqlInfoModel1);
		SqlInfoModel sqlInfoModel2 = new SqlInfoModel();
		sqlInfoModel2.setSqlType("insert");
		sqlInfoModel2.setSqlContent(
				"fid  as fname,fname  as fid");
		sqlInfoModel2.setSqlHistory(
				"fid  as fname,fname  as fid");
		sqlInfoModel2.setSqlSource("mysql");
		hivesql.put("sql3", sqlInfoModel2);
		customReportModel.setHivesql(hivesql);

		Map<String, ColumnInfoModel> mysqlColumn = new HashMap<String, ColumnInfoModel>();
		ColumnInfoModel columnInfoModel = new ColumnInfoModel();
		columnInfoModel.setColumnValue("名字");
		columnInfoModel.setDimType("0");
		columnInfoModel.setColumnType("varchar(200)");

		ColumnInfoModel columnInfoModel1 = new ColumnInfoModel();
		columnInfoModel1.setColumnValue("主键");
		columnInfoModel1.setDimType("1");
		columnInfoModel1.setColumnType("varchar(50)");

		ColumnInfoModel columnInfoModel2 = new ColumnInfoModel();
		columnInfoModel2.setColumnValue("邮箱");
		columnInfoModel2.setDimType("0");
		columnInfoModel2.setColumnType("varchar(100)");
		mysqlColumn.put("fname", columnInfoModel);
		mysqlColumn.put("fid", columnInfoModel1);
		mysqlColumn.put("femail", columnInfoModel2);
		customReportModel.setMysqlColumn(mysqlColumn);

		System.out.println(JSONObject.toJSONString(customReportModel));
	}
}
